package com.practice01.controller;

import org.springframework.boot.CommandLineRunner;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Arrays;

class Person {
    private String name;
    private Integer age;

    public Person(String name, Integer age) {
        this.name = name;
        this.age = age;
    }

    @Override
    public String toString() {
        return "Person{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }
}

@RestController
public class HelloController {
//    @Bean
//    public CommandLineRunner commandLineRunner(ApplicationContext ctx){
//        return args -> {
//            System.out.println("由springbooot注册的所有的bean：");
//            String[] beanNames = ctx.getBeanDefinitionNames();
//            Arrays.sort(beanNames);
//            for (String bean : beanNames){
//                System.out.println(bean);
//            }
//        };
//    }

    @RequestMapping("/")
    public String hello() {
        return "hello";
    }


    @RequestMapping("/getPerson")
    public Person getPerson() {
        Person person = new Person("张三", 12);
        return person;
    }
}
